/*
 * BoardData.cpp
 *
 *  Created on: 13/06/2014
 *      Author: lucio
 */

#include "BoardData.h"

void BoardData::ReloadBoard() {
	this->board->ClearBoard();
	//this->board.AddRows(this->RowCount->get_value_as_int(),
		//	this->ColumnCount->get_value_as_int());
	//this->board.AddColumns(this->RowCount->get_value_as_int(),
		//	this->ColumnCount->get_value_as_int());
	this->board->AddBackground(this->RowCount->get_value_as_int(),
			this->ColumnCount->get_value_as_int());
	this->board->UpdateCellMatrix(this->RowCount->get_value_as_int(),
			this->ColumnCount->get_value_as_int());
}

void BoardData::RowCount_Change() {
	if(this->board->getRowCount() > this->RowCount->get_value_as_int()){
		this->board->setRowCountDec();
	} else {
		this->board->setRowCountInc();
	}
	ReloadBoard();
}

void BoardData::ColumnCount_Change() {
	if(this->board->getColumnCount() > this->ColumnCount->get_value_as_int()){
		this->board->setColumnCountDec();
	} else {
		this->board->setColumnCountInc();
	}
	ReloadBoard();
}

BoardData::BoardData(Glib::RefPtr<Gtk::Builder>& builder, Board* board) {
	this->board = board;
	builder->get_widget("LevelName",this->LevelName);
	builder->get_widget("RowCount",this->RowCount);
	builder->get_widget("ColumnCount",this->ColumnCount);
	builder->get_widget("UpdateButton",this->UpdateButton);

	this->RowCount->set_value((double)this->board->getRowCount());
	this->ColumnCount->set_value((double)this->board->getColumnCount());

	this->RowCount->signal_value_changed().connect(sigc::mem_fun
					(*this,&BoardData::RowCount_Change));
	this->ColumnCount->signal_value_changed().connect(sigc::mem_fun
					(*this,&BoardData::ColumnCount_Change));
}

BoardData::~BoardData() {
	// TODO Auto-generated destructor stub
}

